Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.PowerPacks
Imports MMUtil.clsGeneral
Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
Friend Class frmRes_MEMemo
	Inherits System.Windows.Forms.Form
	Dim SaveFlag As Short
	
	
	'UPGRADE_WARNING: Event cboXExam.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cboXExam_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboXExam.SelectedIndexChanged
		Dim iIndex As Short
		Dim sExam As String
		
		If cboXExam.SelectedIndex < 0 Or cboXExam.SelectedIndex > (cboXExam.Items.Count - 1) Then
			Exit Sub
		End If
		
		IsolateCode((cboXExam.Text))
		sExam = gCode
		
		SQL = "select ResMemo " & CR & "from ExamResMemo " & CR & "Where HID = '" & gHosInfo.HID & "' " & CR & "  and ReceNo = '" & gReceNo & "' " & CR & "  and ExamCode = '" & sExam & "' "
		db_select_Text(SQL, txtRes)
	End Sub
	
	Private Sub cmdCancel_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancel.ClickEvent
		gReturn = 0
		Me.Close()
	End Sub
	
	Private Sub cmdSave_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSave.ClickEvent
		db_BeginTran()
		Dim sCnt As String
		
		SQL = " Select count(*) From ExamResMemo " & CR & "Where HID = '" & gHosInfo.HID & "' " & CR & "  and PID = '" & gPID & "' " & CR & "  and ReceNo = '" & gReceNo & "' " & CR & "  and ExamCode = 'X9999' "
		res = db_select_Var(SQL, sCnt)
		
		If sCnt = "0" Then
			SaveFlag = 0
		Else
			SaveFlag = 1
		End If
		
		If SaveFlag = 0 Then
			SQL = " Insert Into ExamResMemo (HID, PID, ReceNo, ExamCode, ResMemo) " & CR & " Values ('" & gHosInfo.HID & "', '" & gPID & "', '" & gReceNo & "', " & CR & "         'X9999', '" & txtResMemo.Text & "') "
			
			res = SendQuery(SQL)
			
			If res = -1 Then
				db_RollBack()
				SaveQuery(SQL)
				Exit Sub
			End If
			
		Else
			SQL = "Update ExamResMemo " & CR & "Set ResMemo = '" & txtResMemo.Text & "' " & CR & "Where HID = '" & gHosInfo.HID & "' " & CR & "  and PID = '" & gPID & "' " & CR & "  and ReceNo = '" & gReceNo & "' " & CR & "  and ExamCode = 'X9999' "
			
			res = SendQuery(SQL)
			If res = -1 Then
				db_RollBack()
				SaveQuery(SQL)
				Exit Sub
			End If
		End If
		
		db_Commit()
		
		gReturn = 1
		Me.Close()
	End Sub
	
	Private Sub frmRes_MEMemo_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		gReturn = 0
		
		SQL = "Select distinct a.ExamCode, b.ExamAlias, a.Result, a.Decision, a.RefValue " & CR & "from ExamRes a, ExamMaster b" & CR & "Where a.HID = '" & gHosInfo.HID & "' " & CR & "  and a.ReceNo = '" & gReceNo & "' " & CR & "  and isnull(a.Decision,'') <> '' " & CR & "  and b.HID = a.HID " & CR & "  and b.ExamCode = a.ExamCode "
		
		res = db_select_Vas(SQL, vasBad)
		
		If res <> 1 Then
			SaveQuery(SQL)
		End If
		vasBad.MaxRows = vasBad.DataRowCnt
		txtExamCode_TextChanged(txtExamCode, New System.EventArgs())
		
		SQL = "select ResMemo " & CR & "from ExamResMemo " & CR & "Where HID = '" & gHosInfo.HID & "' " & CR & "  and PID = '" & gPID & "' " & CR & "  and ReceNo = '" & gReceNo & "' " & CR & "  and ExamCode = 'X9999' "
		res = db_select_Text(SQL, txtResMemo)
		
		If res <> 1 Then
			SaveQuery(SQL)
		End If
		
		SQL = "select distinct a.ExamCode + '  ' + b.ExamAlias " & CR & "from ExamRes a, ExamMaster b" & CR & "Where a.HID = '" & gHosInfo.HID & "' " & CR & "  and a.ReceNo = '" & gReceNo & "' " & CR & "  and a.ExamCode <> 'X9999' " & CR & "  and b.HID = a.HID " & CR & "  and b.ExamCode = a.ExamCode and b.ResClassCode = '3' "
		
		res = db_select_Combo(SQL, cboXExam)
		
		If res <> 1 Then
			SaveQuery(SQL)
		End If
		
		SQL = "select distinct a.ExamCode, b.ExamAlias " & CR & "from ExamRes a, ExamMaster b" & CR & "Where a.HID = '" & gHosInfo.HID & "' " & CR & "  and a.ReceNo = '" & gReceNo & "' " & CR & "  and a.ExamCode <> 'X9999' " & CR & "  and b.HID = a.HID " & CR & "  and b.ExamCode = a.ExamCode and b.ResClassCode = '3' "
		
		res = db_select_Vas(SQL, vasXExam)
		
		If res <> 1 Then
			SaveQuery(SQL)
		End If
		
	End Sub
	
	Private Sub frmRes_MEMemo_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		'Set frmResMemo = Nothing
	End Sub
	
	Private Sub lstPromise_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lstPromise.DoubleClick
		Dim sMsg As String
		
		sMsg = VB6.GetItemString(lstPromise, lstPromise.SelectedIndex)
		If gHosInfo.HID = "114" Then
			sMsg = Trim(Mid(sMsg, 63))
			txtResMemo.Text = txtResMemo.Text & sMsg & CR
		Else
			sMsg = Trim(Mid(sMsg, 14))
			txtResMemo.Text = txtResMemo.Text & sMsg & CR
		End If
		
	End Sub
	
	'UPGRADE_WARNING: Event txtExamCode.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub txtExamCode_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtExamCode.TextChanged
		lstPromise.Items.Clear()
		
		If gHosInfo.HID = "114" Then
			SQL = "Select convert(char(8),ExamCode) + '  ' +  convert(char(4),SeqNo) + '   ' + convert(char(50),Comment) + '  ' + Remark From MEPromise " & CR & "Where HID = '" & gHosInfo.HID & "' "
			If Trim(txtExamCode.Text) <> "" Then
				SQL = SQL & CR & "  And ExamCode = '" & UCase(txtExamCode.Text) & "' "
			End If
			SQL = SQL & CR & "Order by ExamCode, SeqNo "
			db_select_List(SQL, lstPromise)
		Else
			SQL = "Select convert(char(10),ExamCode) + ' ' +  convert(char(3),SeqNo) + ' '  + Remark From MEPromise " & CR & "Where HID = '" & gHosInfo.HID & "' "
			If Trim(txtExamCode.Text) <> "" Then
				SQL = SQL & CR & "  And ExamCode = '" & UCase(txtExamCode.Text) & "' "
			End If
			SQL = SQL & CR & "Order by ExamCode, SeqNo "
			db_select_List(SQL, lstPromise)
		End If
		
	End Sub
	
	Private Sub vasBad_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As AxFPSpread._DSpreadEvents_DblClickEvent) Handles vasBad.DblClick
		txtExamCode.Text = Trim(GetText(vasBad, eventArgs.Row, 1))
		
	End Sub
	
	Private Sub vasXExam_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxFPSpread._DSpreadEvents_ClickEvent) Handles vasXExam.ClickEvent
		Dim iIndex As Short
		Dim sExam As String
		
		txtRes.Text = ""
		
		sExam = ""
		
		sExam = Trim(GetText(vasXExam, eventArgs.Row, 1))
		
		If sExam = "" Then
			Exit Sub
		End If
		
		SQL = "select ResMemo " & CR & "from ExamResMemo " & CR & "Where HID = '" & gHosInfo.HID & "' " & CR & "  and ReceNo = '" & gReceNo & "' " & CR & "  and ExamCode = '" & sExam & "' "
		db_select_Text(SQL, txtRes)
	End Sub
End Class